package com.colorlight.cloud.grandshow.entity.event;

import com.colorlight.cloud.gateway.api.message.constraint.schedule.ScheduleActions;
import com.colorlight.cloud.grandshow.api.GrandShowEntityEvent;
import com.colorlight.cloud.grandshow.entity.po.AuthInfo;
import com.colorlight.iot.proto.grandshow.event.GrandShowEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author Demon
 * @description 加解密的自动上报（定时上报） AuthorizationInfoEvent = 1017
 * @date 28/4/2024  下午2:59
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class AuthorizationInfo implements GrandShowEntityEvent {
	/**
	 * 设备加解密详情
	 */
	private AuthInfo authInfo;
	
	@Override
	public ScheduleActions byteConvertObject(ByteString bytes) {
		
		GrandShowEvent.AuthorizationInfo authorizationInfo = null;
		try {
			authorizationInfo = GrandShowEvent.AuthorizationInfo.parseFrom(bytes);
		} catch (InvalidProtocolBufferException e) {
			log.error("", e);
		}
		Objects.requireNonNull(authorizationInfo);
		
		this.setAuthInfo(new AuthInfo().formProto(authorizationInfo.getAuthInfo()));
		return this;
	}
}

